<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品查看页面</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        let productId=0;
        let soldNum=0;
        window.onload = function (){
            productId = getQuery("productId");
            soldNum = getQuery("soldNum");
            findById(productId);
        }
        async function findById(id){
            let info = await ajaxGet("/product/findById",{id});
            let str = `商品名：${info.name}<br><br>
                       单价：<input id="price" type="text" value="${info.price}"><br><br>
                       产地：${info.origin}<br><br>
                       生产日期：${info.date}<br><br>
                       已出售：${info.soldNum}件<br><br>
                       <a href="javascript:updatePrice(${info.id})">修改</a>
                        <a style="margin-left: 30px" href="/html/bossIndex.html">返回</a>
                            `;
            $("infoDiv").innerHTML = str;
            $("img").src = "/html/img/"+info.imgPath;
        }
        async function updatePrice(productId,price){
            let info =await ajaxGet("/product/updatePrice",{productId,price:$("price").value});
            if (info == "ok"){
                location.href="/html/boss/bossIndex.html";
            }else {
                alert("修改失败");
            }
        }


    </script>
</head>
<body>
<div style="display: flex; margin-left: 200px;margin-top: 100px">
    <div>
        <img id="img" width="200px" height="260px">
    </div>
    <div style="margin-left: 20px" id="infoDiv"></div>
</div>
</body>
</html>